import { formatDate } from '@/utils/index'
import Vue from 'vue'

Vue.filter('formatDate', (time) => {
    let date = new Date(time);
    return formatDate(date, 'yyyy-MM-dd hh:mm')
})

Vue.filter('formatPercent', (value, decimals) => {
    if(!value) value = 0;
    if(!decimals) decimals = 0;
  
    value = value * 100;
    return Math.round(value * Math.pow(10, decimals)) / Math.pow(10, decimals) + "%";
  })

Vue.filter('formatBranch', branchId => {
  // let branchList = this.$store.state.app.branchList
  let branchList = JSON.parse(sessionStorage.getItem('branch_list'))
  let filterBranch =  branchList.find(element => {
    if (element.branchId === branchId) {
      return element
    }
  })
  return filterBranch.branchName
})